<template>
  <div class="report-form">
    <div class="report-form-content">
      <div class="report-form-content-title">
        <h1 style="font-weight: bold" v-if="oper === 'add'">新增其他报账单</h1>
        <h1 style="font-weight: bold" v-if="oper === 'edit'">修改其他报账单</h1>
        <h1 style="font-weight: bold" v-if="oper === 'view'">查看其他报账单</h1>
        <h1 style="font-weight: bold" v-if="oper === 'supplement'">补充收支信息</h1>
      </div>
      <div style="text-align: right;" v-if="oper === 'supplement'">
        <div class="tabs-list">
          <el-button type="primary" icon="documentAdd" @click="supplementInfo()">保存收支信息</el-button>
        </div>
      </div>
      <div style="text-align: right;" v-if="oper === 'add' || oper === 'edit'">
        <div class="tabs-list">
          <el-button type="success" @click="handleSave()">
            <svg-icon icon-class="save" />
            保存
          </el-button>
          <el-button v-show="checkAuthCode('')" type="primary" @click="handleSubmit()" v-if="obj.id">
            <svg-icon icon-class="submit" />
            提交审批
          </el-button>
        </div>
      </div>
      <div>
        <el-tabs v-model="activeName" class="demo-tabs">
          <el-tab-pane label="报账信息录入" name="1"></el-tab-pane>
          <el-tab-pane label="收支信息录入" name="3"></el-tab-pane>
          <el-tab-pane label="附件上传" name="4"></el-tab-pane>
        </el-tabs>
        <div class="tabs-list" v-show="activeName === '1'">
          <el-form class="my-form"
                   ref="objForm"
                   :model="obj"
                   :rules="rules"
                   label-position="right"
                   label-width="auto"
                   label-suffix="："
                   :disabled="oper === 'view' || oper === 'supplement'">
            <el-row :gutter="20">
              <el-col :sm="24" :lg="24" style="padding-left: 20px">
                <div class="" style="display: flex;align-items: center;justify-content: space-between;">
                  <div></div>
                  <div class="report-form-list-content-1 aggregate" v-if="finalAvailableAmount != null">最大可报账金额: ￥{{ finalAvailableAmount < 0 ? 0 : finalAvailableAmount }}</div>
                </div>
                <el-card class="update-log">
                  <div class="report-form-list-content">
                    <el-form-item label="指标编码">
                      <span>{{ expenditureKpiObj.kpiCode }}</span>
                    </el-form-item>
                    <el-form-item label="指标名称">
                      <span>{{ expenditureKpiObj.kpiName }}</span>
                    </el-form-item>
                    <el-form-item label="可用金额" v-if="getEnv() === 'local'">
                      <span v-if="expenditureKpiObj.kpiCode">￥{{ expenditureKpiObj.availableAmount }}</span>
                    </el-form-item>
                  </div>
                  <div class="report-form-list-content">
                    <el-form-item prop="expenditureKpiId">
                      <el-button type="primary" icon="search" @click="chooseExpenditureKpi">选择指标单</el-button>
                    </el-form-item>
                    <el-button :disabled="!expenditureKpiObj.id" style="margin-left: 16px" @click="expenditureKpiDrawer = true">
                      <svg-icon icon-class="view" />查看详情
                    </el-button>
                    <el-drawer v-model="expenditureKpiDrawer" title="指标单详情">
                      <div class="report-form-list-content report-form-list-content-be">
                        <el-form label-suffix="：">
                          <el-form-item label="预算年度">
                            <span>{{ expenditureKpiObj.year }}</span>
                          </el-form-item>
                          <el-form-item label="支出类型">
                            <span>
                              <DictTag :dict-list="getDictList('ExpenditureKpiPayType')" :dict-key="expenditureKpiObj.payType" />
                            </span>
                          </el-form-item>
                          <el-form-item label="经费类型">
                            <span>
                              <DictTag :dict-list="getDictList('ExpenditureKpiFundType')" :dict-key="expenditureKpiObj.fundType" />
                            </span>
                          </el-form-item>
                          <el-form-item label="预算总金额">
                            <MoneyTag :money="expenditureKpiObj.amount" />
                          </el-form-item>
                          <el-form-item label="可用金额">
                            <MoneyTag :money="expenditureKpiObj.availableAmount" />
                          </el-form-item>
                          <el-form-item label="项目负责人部门">
                            <span>{{ showIdLabel(organizationList, expenditureKpiObj.organizationId, 'organizationName') }}</span>
                          </el-form-item>
                          <el-form-item label="项目负责人">
                            <span>{{ showIdLabel(userList, expenditureKpiObj.managerId, 'name') }}</span>
                          </el-form-item>
                          <el-form-item label="功能分类">
                            <span>{{ showIdLabel(expenditureFunctionalList, expenditureKpiObj.expenditureFunctionalId, 'name') }}</span>
                          </el-form-item>
                          <el-form-item label="财政项目">
                            <span>{{ showIdLabel(expenditureFiscalList, expenditureKpiObj.expenditureFiscalId, 'name') }}</span>
                          </el-form-item>
                          <el-form-item label="指标来源">
                            <span>
                              <DictTag :dict-list="getDictList('ExpenditureKpiSource')" :dict-key="expenditureKpiObj.source" />
                            </span>
                          </el-form-item>
                          <el-form-item label="项目类型">
                            <span>{{ showIdLabel(expenditurePtypeList, expenditureKpiObj.expenditurePtypeId, 'name') }}</span>
                          </el-form-item>
                          <el-form-item label="指标单状态">
                            <span>
                              <EnumTag :enum-list="getEnumList('ExpenditureKpiState')" :enum-key="expenditureKpiObj.state" />
                            </span>
                          </el-form-item>
                          <el-form-item label="按经济分类控制金额">
                            <span>
                              <EnumTag :enum-list="getEnumList('CommonYesNo')" :enum-key="expenditureKpiObj.isEconomic" />
                            </span>
                          </el-form-item>
                        </el-form>
                      </div>
                    </el-drawer>
                  </div>
                </el-card>
              </el-col>
              <el-col :sm="24" :lg="24" style="padding-left: 20px">
                <el-card class="update-log">
                  <div class="report-form-list-content">
                    <el-form-item label="申请单号">
                      <span>{{ expenditureApplicationObj.applicationCode }}</span>
                    </el-form-item>
                    <el-form-item label="申请金额">
                      <span v-if="expenditureApplicationObj.applicationCode">
                        <MoneyTag :money="expenditureApplicationObj.amount" />
                      </span>
                    </el-form-item>
                    <el-form-item label="可用金额" v-if="getEnv() === 'local'">
                      <span v-if="expenditureApplicationObj.applicationCode">￥{{ expenditureApplicationObj.availableAmount }}</span>
                    </el-form-item>
                  </div>
                  <div class="report-form-list-content">
                    <el-form-item prop="expenditureApplicationId">
                      <el-button type="primary" icon="search" @click="chooseExpenditureApplication">选择事前用款申请单</el-button>
                    </el-form-item>
                    <el-button :disabled="!expenditureApplicationObj.id" style="margin-left: 16px" @click="expenditureApplicationDrawer = true">
                      <svg-icon icon-class="view" />查看详情
                    </el-button>
                    <el-drawer v-model="expenditureApplicationDrawer" title="事前用款申请单详情">
                      <div class="report-form-list-content report-form-list-content-be">
                        <el-form label-suffix="：">
                          <el-form-item label="申请单号">
                            <text>{{ expenditureApplicationObj.applicationCode }}</text>
                          </el-form-item>
                          <el-form-item label="申请日期">
                            <text>{{ expenditureApplicationObj.applicationDate?.substring(0, 10) }}</text>
                          </el-form-item>
                          <el-form-item label="申请人部门">
                            <text>{{ showIdLabel(organizationList, expenditureApplicationObj.applicationOrganizationId, 'organizationName') }}</text>
                          </el-form-item>
                          <el-form-item label="申请人用户">
                            <text>{{ showIdLabel(userList, expenditureApplicationObj.applicationUserId, 'name') }}</text>
                          </el-form-item>
                          <el-form-item label="事前用款申请单类型">
                            <span>
                              <DictTag :dict-list="getDictList('ExpenditureApplicationType')" :dict-key="expenditureApplicationObj.applicationType" />
                            </span>
                          </el-form-item>
                          <el-form-item label="申请金额">
                            <MoneyTag :money="expenditureApplicationObj.amount" />
                          </el-form-item>
                          <el-form-item label="请款事由">
                            <text>{{ expenditureApplicationObj.items }}</text>
                          </el-form-item>
                          <el-form-item label="支出事项">
                            <text>{{ expenditureApplicationObj.reason }}</text>
                          </el-form-item>
                          <el-form-item label="备注">
                            <text>{{ expenditureApplicationObj.remark }}</text>
                          </el-form-item>
                        </el-form>
                      </div>
                    </el-drawer>
                  </div>
                </el-card>
              </el-col>
              <el-col :sm="24" :lg="24" style="padding-left: 20px">
                <el-card class="update-log">
                  <div class="report-form-list-content">
                    <el-form-item label="经济分类" prop="expenditureEconomicId">
                      <el-cascader v-model="obj.expenditureEconomicId"
                                   :options="arrChangeTreeFn(expenditureEconomicList)"
                                   :props="{label: 'name', value: 'id'}"
                                   :show-all-levels="false"
                                   @change="changeExpenditureEconomicId"
                                   clearable
                                   filterable>
                        <template #default="{ data }">
                          <span>{{ data.code }}</span>
                          <span style="padding: 0 5px">-</span>
                          <span>{{ data.name }}</span>
                        </template>
                      </el-cascader>
                    </el-form-item>
                    <el-form-item label="可用金额" v-if="getEnv() === 'local'">
                      <span v-if="available">￥{{ available }}</span>
                    </el-form-item>
                    <el-divider />
                    <el-form-item label="报账单号" prop="reimbursementCode">
                      <el-input v-model="obj.reimbursementCode" placeholder="自动生成" disabled />
                    </el-form-item>
                    <el-form-item label="报账日期" prop="reimbursementDate">
                      <el-date-picker v-model="obj.reimbursementDate" type="date" placeholder="选择日期" value-format="YYYY-MM-DD" />
                    </el-form-item>
                    <el-form-item label="申请人部门" prop="applicationOrganizationId">
                      <Organization v-model="obj.applicationOrganizationId" keyName="id" keyShow="organizationName" placeholder="申请人部门" title="部门查询" />
                    </el-form-item>
                    <el-form-item label="申请人用户" prop="applicationUserId">
                      <User v-model="obj.applicationUserId" keyName="id" keyShow="name" placeholder="申请人用户" title="用户查询" />
                    </el-form-item>
                    <el-form-item label="会计科目" prop="expenditureSubjectId">
                      <el-cascader v-model="obj.expenditureSubjectId" :options="arrChangeTreeFn(expenditureSubjectList)" :props="{label: 'name', value: 'id'}" :show-all-levels="false" clearable filterable>
                        <template #default="{ data }">
                          <span>{{ data.code }}</span>
                          <span style="padding: 0 5px">-</span>
                          <span>{{ data.name }}</span>
                        </template>
                      </el-cascader>
                    </el-form-item>
                    <el-form-item label="结算方式" prop="settlement">
                      <el-select v-model="obj.settlement" class="m-2" placeholder="请选择">
                        <el-option v-for="item in getDictList('ExpenditureSettlement')" :key="item.key" :label="`${item.key} - ${item.value}`" :value="item.key" />
                      </el-select>
                    </el-form-item>
                    <el-form-item label="金额" prop="amount">
                      <el-input-number v-model="obj.amount" placeholder="金额" :min="0" :precision="2" />
                    </el-form-item>
                  </div>
                  <div class="report-form-list-content-1">
                  <el-form-item label="摘要" prop="remark">
                    <el-input v-model="obj.remark" :autosize="{ minRows: 2, maxRows: 5}" type="textarea" class="textarea-1" />
                  </el-form-item>
                </div>
                </el-card>
              </el-col>
            </el-row>
          </el-form>
          <el-divider />
        </div>
        <div class="tabs-list" v-show="activeName === '3'">
          <el-row :gutter="20">
            <el-col :sm="24" :lg="24" style="padding-left: 20px">
              <h3>支出信息</h3>
              <el-card class="update-log" v-for="(pay, idx) in pays" :key="idx">
                <el-form class="my-form" ref="outcomeForm" :model="pay" :rules="ruleForSupplement" label-position="right" label-width="7rem" :disabled="oper === 'view'">
                  <div class="report-form-list-content">
                    <el-form-item label="支付方式" prop="payType">
                      <el-select v-model="pay.payType" class="m-2" placeholder="请选择">
                        <el-option v-for="item in getDictList('ExpenditurePay')" :key="item.key" :label="`${item.key} - ${item.value}`" :value="item.key" />
                      </el-select>
                    </el-form-item>
                    <el-form-item label="结算方式" prop="settleType">
                      <el-select v-model="pay.settleType" class="m-2" placeholder="请选择">
                        <el-option v-for="item in getDictList('ExpenditureSettlement')" :key="item.key" :label="`${item.key} - ${item.value}`" :value="item.key" />
                      </el-select>
                    </el-form-item>
                    <el-form-item label="支付账户" prop="payAccount">
                      <el-select v-model="pay.payAccount" class="m-2" placeholder="请选择" clearable filterable>
                        <el-option v-for="item in accountList" :key="item.id" :label="`${item.accountCode} - ${item.accountName}`" :value="item.id"/>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="收付标识" prop="pay">
                      <el-radio-group v-model="pay.pay" disabled>
                        <el-radio-button v-for="(item,index) in getEnumList('ExpenditurePay')" :label="item.key" :key="index">{{item.value}}</el-radio-button>
                      </el-radio-group>
                    </el-form-item>
                    <el-form-item label="金额" prop="amount">
                      <el-input-number v-model="pay.amount" :min="0" :precision="2" disabled />
                    </el-form-item>
                  </div>
                  <div class="report-form-list-content-1">
                    <el-form-item label="摘要" prop="paySummary">
                      <el-input v-model="pay.paySummary" :rows="5" type="textarea" class="textarea-1" />
                    </el-form-item>
                  </div>
                </el-form>
              </el-card>
            </el-col>
            <el-col :sm="24" :lg="24" style="padding-left: 20px">
              <div class="report-form-list-content" style="align-items: center;">
                <h3 style="margin-right: 20px">收款方信息</h3>
              </div>
              <el-card class="update-log" v-for="(payee, idx) in payees" :key="idx">
                <el-form class="my-form" ref="incomeForm" :model="payee" :rules="ruleForSupplement" label-position="right" label-width="7rem" :disabled="oper === 'view'">
                  <div class="report-form-list-content">
                    <el-form-item label="收款类型" prop="payeeType">
                      <el-radio-group v-model="payee.payeeType" @change="changePayeeType">
                        <el-radio-button v-for="(item,index) in getEnumList('ExpenditureReimbursementPayeeType')" :label="item.key" :key="index">{{item.value}}</el-radio-button>
                      </el-radio-group>
                    </el-form-item>
                  </div>
                  <el-divider />
                  <div class="report-form-list-content" v-if="payee.payeeType === '1'">
                    <el-form-item label="选择收款单位" prop="expenditureProceedsId">
                      <el-select v-model="expenditureProceedsItem" class="m-2" placeholder="请选择" clearable filterable value-key="id" @change="changeProceeds">
                        <el-option v-for="item in proceedsList" :key="item.id" :label="`${item.code} - ${item.name}`" :value="item" />
                      </el-select>
                    </el-form-item>
                    <el-divider style="border: 0 !important;" />
                    <el-form-item label="收款单位名称" prop="proceedsCompany">
                      <el-input v-model="payee.proceedsCompany" />
                    </el-form-item>
                    <el-form-item label="收款银行" prop="proceedsBank">
                      <el-select v-model="payee.proceedsBank" class="m-2" placeholder="请选择" clearable filterable>
                        <el-option v-for="item in bankList" :key="item.id" :label="`${item.bankCode} - ${item.bankName}`" :value="item.id" />
                      </el-select>
                    </el-form-item>
                    <el-form-item label="收款账号" prop="proceedsAccount">
                      <el-input v-model="payee.proceedsAccount" />
                    </el-form-item>
                  </div>
                  <div class="report-form-list-content" v-if="payee.payeeType === '2'">
                    <el-form-item label="选择用户公务卡" prop="expenditureBusinessCardId">
                      <el-select v-model="payee.expenditureBusinessCardId" class="m-2" placeholder="请选择" clearable filterable value-key="id" @change="changeBusinessCard">
                        <el-option v-for="item in businessCardList" :key="item.id" :label="`${item.cardName}`" :value="item"/>
                      </el-select>
                    </el-form-item>
                    <el-divider style="border: 0 !important;" />
                    <el-form-item label="公务卡持有人" prop="businessCardName">
                      <el-input v-model="payee.businessCardName" />
                    </el-form-item>
                    <el-form-item label="开户行" prop="businessCardBank">
                      <el-select v-model="payee.businessCardBank" class="m-2" placeholder="请选择" clearable filterable>
                        <el-option v-for="item in bankList" :key="item.id" :label="`${item.bankCode} - ${item.bankName}`" :value="item.id" />
                      </el-select>
                    </el-form-item>
                    <el-form-item label="卡号" prop="businessCardAccount">
                      <el-input v-model="payee.businessCardAccount" />
                    </el-form-item>
                  </div>
                  <div class="report-form-list-content-1">
                    <el-form-item label="摘要" prop="payeeSummary">
                      <el-input v-model="payee.payeeSummary" :rows="5" type="textarea" class="textarea-1" />
                    </el-form-item>
                  </div>
                </el-form>
              </el-card>
            </el-col>
          </el-row>
          <el-divider />
        </div>
        <div class="tabs-list" v-show="activeName === '4'">
          <el-form class="my-form" ref="obj111" :model="obj" :rules="rules" label-position="right" label-width="auto" :disabled="oper === 'view' || oper === 'supplement'">
            <!-- 附件信息 -->
            <div class="file-list-btn">
              <span class="file-list-btn-span">*温馨提示:保存成功后才能预览word文档和Excel报表</span>
              <div class="file-list-btns">
                <el-button type="primary" plain style="margin-right:1rem;" @click="selectAttachmentBtn"><svg-icon icon-class="search" />选择已上传的文件</el-button>
                <FileUpload :isShowTip="false" v-model="oFiles" :isShowFileList="false" @uploadedSuccess="uploadedSuccessFn" />
              </div>
            </div>
            <el-table :data="oFiles"
                      style="width: 100%; margin-top: 20px"
                      row-key="id"
                      border
                      default-expand-all
                      @selection-change="handleSelectionChange">
              <el-table-column type="selection" width="55" />
              <el-table-column label="附件类型">
                <template v-slot="{row}">
                  <el-form-item prop="attachmentType" style="margin: 0 auto;">
                    <el-select v-model="row.attachmentType" class="m-2" placeholder="请选择">
                      <el-option v-for="item in getEnumList('ExpenditureReimbursementFeetype')" :key="item.key" :label="item.value" :value="item.key" />
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column prop="original" label="附件名称" />
              <el-table-column align="center" label="操作" width="160px" fixed="right">
                <template #default="scope">
                  <el-button type="primary" link @click="downloadFile1(scope.row)">下载</el-button>
                  <el-button type="primary" link @click="viewFile1(scope.row)">预览</el-button>
                  <el-button type="danger" link @click="removeFile1(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-form>
        </div>
      </div>
    </div>
    <el-dialog v-model="attachmentVisible" title="附件预览" width="70%" top="2vh">
      <attachmentPreview v-model:attachmentId="previewAttachmentId" />
      <div style="text-align:right;">
        <el-button type="danger" @click="attachmentVisible = false">关闭</el-button>
      </div>
    </el-dialog>
    <selectExpenditureKpiList v-model:itemsVisible="itemsVisible"
                              :expenditureKpiId="obj.expenditureKpiId || ''"
                              @close="itemsVisible = false"
                              @expenditureKpiSelect="changeExpenditureKpi" />
    <selectExpenditureApplicationList v-model:itemsVisible="applicationVisible"
                                      :expenditureKpiId="expenditureKpiObj.id || ''"
                                      :expenditureKpiCode="expenditureKpiObj.kpiCode || ''"
                                      :expenditureApplicationId="obj.expenditureApplicationId || ''"
                                      @close="applicationVisible = false"
                                      @expenditureApplicationSelect="changeExpenditureApplication" />
    <selectApprove v-model:itemsVisible="dialogApproveVisible" @close="dialogApproveVisible = false" :business="'2006'" :businessId="obj.id" @doSubmit="doSubmit" />
    <el-dialog v-model="selectAttachmentVisible" title="选择附件" width="70%" top="2vh">
      <selectAttachmentMultiple :isVisible="selectAttachmentVisible" @selectAttachment="selectAttachmentFn" @close="selectAttachmentVisible = false"></selectAttachmentMultiple>
    </el-dialog>
  </div>
</template>
<script setup>
import {ref, getCurrentInstance, computed} from 'vue'
import {doGet, doPost, doDownload} from '@/config/http'
import {
  alertErrorMsg, alertWarningMsg, checkAuthCode,
  customValidator,
  getDictList,
  getEnumList, getEnv,
  getListPageSize, isNullOrUndefined, isNullOrUndefinedOrEmpty,
  notifySuccess,
  showIdLabel,
  svc
} from "@/config/common"
import selectExpenditureKpiList from '@/views/components/expenditure/selectExpenditureKpiList.vue'
import selectExpenditureApplicationList from '@/views/components/expenditure/selectExpenditureApplicationList.vue'
import selectAttachmentMultiple from '@/views/components/base/selectAttachmentMultiple.vue'
import attachmentPreview from '@/views/components/base/attachmentPreview.vue'
import selectApprove from "@/views/components/base/selectApprove.vue";
import {parseTime} from "@/utils/ruoyi";
import {getUserId} from "@/config/cookie";
import useUserStore from "@/store/modules/user";
import {useRoute, useRouter} from 'vue-router'
import SvgIcon from "@/components/SvgIcon/index.vue";
import User from "@/views/components/base/selectUser.vue";
import Organization from "@/views/components/base/selectOrganization.vue";
import initListStore from '@/store/modules/initList'

const router = useRouter()
const route = useRoute()

// 使用this方法(有几个方法不好改，换一种方式使用this) ctx代替this
const { proxy: ctx } = getCurrentInstance();

const emptyObj = {
  expenditureApplicationId: null,	// 事前用款申请单ID		false
  expenditureEconomicId: null,	// 经济分类ID		false
  expenditureKpiId: null,	// 指标单表ID		false
  expenditureSubjectId: null,	// 会计科目ID		false
  reimbursementType: '1', // 报账单类型
  reimbursementCode: null,	// 报账单号		false
  reimbursementDate: parseTime(new Date().getTime(), '{y}-{m}-{d}'),	// 报账日期		false
  amount: 0,	// 金额		false
  settlement: null,	// 结算方式		false
  applicationOrganizationId: useUserStore().organization.id, // 申请人部门ID
  applicationUserId: getUserId(), // 申请人用户ID
  state: null,	// 状态		false
  approveId: null,
  id: null,	// 主键ID		false
  createBy: null,	// 创建人用户ID		false
  createTime: null,	// 创建时间		false
  updateBy: null,	// 最后修改人用户ID		false
  updateTime: null,	// 最后修改时间		false
  version: null,	// 数据版本		false

  pays: [],
  payees: [],
  itemFiles: [],
}
const emptyPay = {
  expenditureReimbursementId: null, // 报账单ID
  payType: null, // 支付方式
  settleType: null, // 结算方式
  payAccount: null, // 支付账户
  pay: '0', // 收付标识
  amount: null, // 金额
  paySummary: null, // 摘要
  id: null,
  createBy: null,
  createTime: null,
  updateBy: null,
  updateTime: null,
  deleted: null,
  version: null,
}
const emptyPayee = {
  expenditureReimbursementId: null, // 报账单ID
  payeeType: null, // 收款类型
  expenditureProceedsId: null, // 收款单位ID
  proceedsCompany: null, // 收款单位名称
  proceedsBank: null, // 收款银行
  proceedsAccount: null, // 收款账号
  expenditureBusinessCardId: null, // 公务卡持卡人用户ID
  businessCardName: null, // 公务卡持卡人
  businessCardBank: null, // 公务卡开户银行
  businessCardAccount: null, // 公务卡号
  payeeSummary: null, // 摘要
  id: null,
  createBy: null,
  createTime: null,
  updateBy: null,
  updateTime: null,
  deleted: null,
  version: null,
}
let incomeForm = ref(null)
let outcomeForm = ref(null)
let expenseTypeValues = ref([])
let obj = ref(Object.assign({}, emptyObj))
let routes = ref([])
let oper = ref('')
let id = ref('')
let activeName = ref('1')
let attachmentVisible = ref(false)
let previewAttachmentId = ref('')
let dialogApproveVisible = ref(false)
let pays = ref([ Object.assign({}, emptyPay) ])
let payees = ref([Object.assign({}, emptyPayee) ])
let tableKey = ref(0)
let list = ref(null)
let total = ref(0)
let listLoading = ref(false)
let itemsVisible = ref(false)
let applicationVisible = ref(false)
let approveList = ref([])
let rules = ref({
  expenditureKpiId: [{ required: true, validator: customValidator, min: 1, max: 100, label: '指标单', trigger: ['blur', 'change'] }],
  expenditureApplicationId: [{ required: false, validator: customValidator, min: 0, max: 100, label: '事前用款申请单', trigger: ['blur', 'change'] }],
  reimbursementType: [{ required: false, validator: customValidator, min: 0, max: 20, label: '报账单类型', trigger: ['blur', 'change'] }],
  reimbursementCode: [{ required: false, validator: customValidator, min: 0, max: 100, label: '报账单号', trigger: ['blur', 'change'] }],
  reimbursementDate: [{ required: true, validator: customValidator, min: 0, max: 100, label: '报账日期', trigger: ['blur', 'change'] }],
  expenditureEconomicId: [{ required: false, validator: customValidator, min: 0, max: 100, label: '经济分类', trigger: ['blur', 'change'] }],
  expenditureSubjectId: [{ required: true, validator: customValidator, min: 0, max: 100, label: '会计科目', trigger: ['blur', 'change'] }],
  amount: [{ required: true, validator: customValidator, min: 0, max: 13, label: '金额', trigger: ['blur', 'change'] }],
  settlement: [{ required: false, validator: customValidator, min: 0, max: 100, label: '结算方式', trigger: ['blur', 'change'] }],
  applicationOrganizationId: [{ required: true, validator: customValidator, min: 0, max: 20, label: '申请人部门', trigger: ['blur', 'change'] }],
  applicationUserId: [{ required: true, validator: customValidator, min: 0, max: 20, label: '申请人用户', trigger: ['blur', 'change'] }],
  state: [{ required: false, validator: customValidator, min: 0, max: 100, label: '状态', trigger: ['blur', 'change'] }],
  invoiceCode: [{ required: true, validator: customValidator, min: 0, max: 100, label: '发票代码', trigger: ['blur', 'change'] }],
  invoiceNumber: [{ required: true, validator: customValidator, min: 0, max: 100, label: '发票号码', trigger: ['blur', 'change'] }],
})
let ruleForSupplement = ref({
  //expenditureReimbursementId: [{ required: false, validator: customValidator, min: 0, max: 20, label: '报账单ID', trigger: ['blur', 'change'] }],
  payType: [{ required: true, validator: customValidator, min: 0, max: 20, label: '支付方式', trigger: ['blur', 'change'] }],
  settleType: [{ required: false, validator: customValidator, min: 0, max: 20, label: '结算方式', trigger: ['blur', 'change'] }],
  payAccount: [{ required: false, validator: customValidator, min: 0, max: 200, label: '支付账户', trigger: ['blur', 'change'] }],
  pay: [{ required: false, validator: customValidator, min: 0, max: 20, label: '收付标识', trigger: ['blur', 'change'] }],
  amount: [{ required: false, validator: customValidator, min: 0, max: 13, label: '金额', trigger: ['blur', 'change'] }],
  paySummary: [{ required: false, validator: customValidator, min: 0, max: 0, label: '摘要', trigger: ['blur', 'change'] }],

  //expenditureReimbursementId: [{ required: false, validator: customValidator, min: 0, max: 20, label: '报账单ID', trigger: ['blur', 'change'] }],
  payeeType: [{ required: false, validator: customValidator, min: 0, max: 20, label: '收款类型', trigger: ['blur', 'change'] }],
  expenditureProceedsId: [{ required: false, validator: customValidator, min: 0, max: 20, label: '收款单位ID', trigger: ['blur', 'change'] }],
  proceedsCompany: [{ required: false, validator: customValidator, min: 0, max: 200, label: '收款单位名称', trigger: ['blur', 'change'] }],
  proceedsBank: [{ required: false, validator: customValidator, min: 0, max: 200, label: '收款银行', trigger: ['blur', 'change'] }],
  proceedsAccount: [{ required: false, validator: customValidator, min: 0, max: 200, label: '收款账号', trigger: ['blur', 'change'] }],
  expenditureBusinessCardId: [{ required: false, validator: customValidator, min: 0, max: 20, label: '公务卡持卡人用户ID', trigger: ['blur', 'change'] }],
  businessCardName: [{ required: false, validator: customValidator, min: 0, max: 200, label: '公务卡持卡人', trigger: ['blur', 'change'] }],
  businessCardBank: [{ required: false, validator: customValidator, min: 0, max: 200, label: '公务卡开户银行', trigger: ['blur', 'change'] }],
  businessCardAccount: [{ required: false, validator: customValidator, min: 0, max: 200, label: '公务卡号', trigger: ['blur', 'change'] }],
  payeeSummary: [{ required: false, validator: customValidator, min: 0, max: 0, label: '摘要', trigger: ['blur', 'change'] }],
})

let expenditureKpiDrawer = ref(false)
let expenditureApplicationDrawer = ref(false)

let expenditureProceedsItem = ref(null)

const available = ref(null) //按经济分类的可用金额

const finalAvailableAmount = computed(() => {
  if (isNullOrUndefined(expenditureKpiObj.value.availableAmount)) {
    return null
  }
  let r = expenditureKpiObj.value.availableAmount
  if (!isNullOrUndefined(expenditureApplicationObj.value.availableAmount)) {
    r = Math.min(r, expenditureApplicationObj.value.availableAmount)
  }
  if (!isNullOrUndefined(available.value)) {
    r = Math.min(r, available.value)
  }
  return r
})

let governmentList = initListStore().governmentList
let organizationList = initListStore().organizationList
let userList = initListStore().userList
let expenditurePtypeList = initListStore().expenditurePtypeList//项目类型
let expenditureFunctionalList = initListStore().expenditureFunctionalList//功能分类
let expenditureEconomicList = initListStore().expenditureEconomicList//经济分类
let expenditureFiscalList = initListStore().expenditureFiscalList//财政项目
let expenditureSubjectList = initListStore().expenditureSubjectList//会计科目
let accountList = initListStore().accountList//
let proceedsList = initListStore().proceedsList//
let businessCardList = initListStore().businessCardList//
let bankList = initListStore().bankList//
let expenditureKpiObj = ref({
  kpiCode: null, // 指标编码
  kpiName: null, // 指标名称
  kpiDate: null, // 单据日期
  year: null, // 预算年度
  payType: null, // 支出类型
  fundType: null, // 经费类型
  amount: null, // 预算总金额
  organizationId: null, // 项目负责人部门ID
  managerId: null, // 项目负责人
  expenditurePtypeId: null, // 项目类型ID
  expenditureFunctionalId: null, // 功能分类ID
  expenditureFiscalId: null, // 财政项目ID
  source: null, // 指标来源
  state: null, // 状态
  isEconomic: null, // 按经济分类控制金额
  availableAmount: null,
})
let expenditureApplicationObj = ref({
  applicationCode: null, // 申请单号
  applicationDate: null, // 申请日期
  applicationType: null, // 类型
  amount: null, // 申请金额
  items: null, // 请款事项
  reason: null, // 支出事由
  state: null, // 状态
  remark: null, // 备注
  availableAmount: null,
})

let oFiles = ref([])

let dialogViewVisible = ref(null)

let objForm = ref(null)
let approveIdObjForm = ref(null)

let selectAttachmentVisible = ref(false)

const arrChangeTreeFn = (list, pid = null, parentLevel = 0) => {
  if (!list) {
      return null
  }
  return list
  .filter((item) =>
    !pid ? item.parentId === null : item.parentId === pid
  )
  .map(item => {
    item.level = parentLevel + 1
    item.children = arrChangeTreeFn(list, item.id, parentLevel + 1);
    return item;
  });
}

// const initList = async () => {
//   let p1 = doGet(svc, '/government/page', {pageSize: getListPageSize()}, false)
//   let p2 = doGet(svc, '/organization/page', {pageSize: getListPageSize()}, false)
//   let p3 = doGet(svc, '/user/page', {pageSize: getListPageSize()}, false)
//   let p4 = doGet(svc, '/expenditure-ptype/page', {pageSize: getListPageSize()}, false)
//   let p5 = doGet(svc, '/expenditure-functional/page', {pageSize: getListPageSize()}, false)
//   let p6 = doGet(svc, '/expenditure-economic/page', {pageSize: getListPageSize()}, false)
//   let p7 = doGet(svc, '/expenditure-fiscal/page', {pageSize: getListPageSize()}, false)
//   let p8 = doGet(svc, '/expenditure-subject/page', {pageSize: getListPageSize()}, false)
//   let p9 = doGet(svc, '/expenditure-feetype-file/page', {pageSize: getListPageSize()}, false) // 费用类型附件
//   let p10 = doGet(svc, '/expenditure-reimbursement-item-file/page', {pageSize: getListPageSize()}, false)
//   let p11 = doGet(svc, '/expenditure-account/page', {state: '1', pageSize: getListPageSize()}, false)
//   let p12 = doGet(svc, '/expenditure-proceeds/page', {state: '1', pageSize: getListPageSize()}, false)
//   let p13 = doGet(svc, '/expenditure-business-card/page', {state: '1', pageSize: getListPageSize()}, false)
//   let p14 = doGet(svc, '/bank/page', {state: '1', pageSize: getListPageSize()}, false)
//   let resArray = await Promise.all([p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14])
//   governmentList.value = resArray[0]['records']
//   organizationList.value = resArray[1]['records']
//   userList.value = resArray[2]['records']
//   expenditurePtypeList.value = resArray[3]['records']
//   expenditureFunctionalList.value = resArray[4]['records']
//   expenditureEconomicList.value = resArray[5]['records']
//   expenditureFiscalList.value = resArray[6]['records']
//   expenditureSubjectList.value = resArray[7]['records']
//   accountList.value = resArray[10]['records']
//   proceedsList.value = resArray[11]['records']
//   businessCardList.value = resArray[12]['records']
//   bankList.value = resArray[13]['records']
// }
const initObj = async () =>  {
  oper.value = route.query.oper
  id.value = null
  if (route.query.id) {
    id.value = route.query.id
    obj.value = await doGet(svc, '/expenditure-reimbursement/' + id.value, {}, true)
    obj.value.expenditureEconomicId = obj.value.expenditureEconomicId?.split(',')
    obj.value.expenditureSubjectId = obj.value.expenditureSubjectId?.split(',')

    // expenditureProceedsItem.value =
    console.debug('obj', obj.value)
    oFiles.value = await doGet(svc, '/expenditure-reimbursement-file/listByField', {field: 'expenditureReimbursementId', values: id.value}, false)
    oFiles.value = oFiles.value.map(item => {
      item.original = item.attachmentName
      // item.fileType = item.attachmentType
      return item
    })
    console.debug('oFiles.value',oFiles.value)
    pays.value = await doGet(svc, '/expenditure-reimbursement-pay/listByField', {field: 'expenditureReimbursementId', values: id.value}, false)
    emptyPay.amount = obj.value.amount
    if (pays.value.length === 0) {
      pays.value.push(emptyPay)
    }
    payees.value = await doGet(svc, '/expenditure-reimbursement-payee/listByField', {field: 'expenditureReimbursementId', values: id.value}, false)
    emptyPayee.amount = obj.value.amount
    if (payees.value.length === 0) {
      payees.value.push(emptyPayee)
    } else {
      expenditureProceedsItem.value = proceedsList.value.filter(item => item.id === payees.value[0].expenditureProceedsId)[0]
    }
    if (!isNullOrUndefinedOrEmpty(obj.value.expenditureKpiId)) {
      expenditureKpiObj.value = await doGet(svc, `/expenditure-kpi/${obj.value.expenditureKpiId}`, {}, false)
      expenditureKpiObj.value.availableAmount = await doGet(svc, '/customExpenditureKpis/queryExpenditureKpiAvailableAmount', {expenditureKpiId: obj.value.expenditureKpiId}, false)
      await changeExpenditureKpi(expenditureKpiObj.value, obj.value.expenditureApplicationId)
    }
    if (!isNullOrUndefinedOrEmpty(obj.value.expenditureApplicationId)) {
      expenditureApplicationObj.value = await doGet(svc, `/expenditure-application/${obj.value.expenditureApplicationId}`, {}, false)
      expenditureApplicationObj.value.availableAmount = await doGet(svc, '/customExpenditureExpenses/queryExpenditureApplicationAvailableAmount', {expenditureApplicationId: obj.value.expenditureApplicationId}, false)
      await changeExpenditureApplication(expenditureApplicationObj.value)
    }
    changeExpenditureEconomicId()
    console.debug('expenseTypeValues',expenseTypeValues.value)
    if (oper.value === 'supplement') {
      activeName.value = '3'
      ruleForSupplement.value.payType[0].required = true
      ruleForSupplement.value.settleType[0].required = true
      ruleForSupplement.value.payAccount[0].required = true
      ruleForSupplement.value.pay[0].required = true
      ruleForSupplement.value.amount[0].required = true
      ruleForSupplement.value.payeeType[0].required = true
    }
  }
}

initObj()
// initList()

const changePayeeType = (o) => {
  switch (o) {
    case "1":
      ruleForSupplement.value.expenditureProceedsId[0].required = true
      ruleForSupplement.value.proceedsCompany[0].required = true
      ruleForSupplement.value.proceedsBank[0].required = true
      ruleForSupplement.value.proceedsAccount[0].required = true
      ruleForSupplement.value.expenditureBusinessCardId[0].required = false
      ruleForSupplement.value.businessCardName[0].required = false
      ruleForSupplement.value.businessCardBank[0].required = false
      ruleForSupplement.value.businessCardAccount[0].required = false
      break
    case "2":
      ruleForSupplement.value.expenditureProceedsId[0].required = false
      ruleForSupplement.value.proceedsCompany[0].required = false
      ruleForSupplement.value.proceedsBank[0].required = false
      ruleForSupplement.value.proceedsAccount[0].required = false
      ruleForSupplement.value.expenditureBusinessCardId[0].required = true
      ruleForSupplement.value.businessCardName[0].required = true
      ruleForSupplement.value.businessCardBank[0].required = true
      ruleForSupplement.value.businessCardAccount[0].required = true
      break
  }
}

const selectAttachmentBtn = () => {
  selectAttachmentVisible.value = true
}
const chooseExpenditureKpi = () => {
  itemsVisible.value = true
}
const changeExpenditureKpi = async (data, expenditureApplicationId) => {
  expenditureKpiObj.value = data
  obj.value.expenditureKpiId = data.id
  // 重置申请单
  expenditureApplicationObj.value = {}
  obj.value.expenditureApplicationId = expenditureApplicationId
  rules.value.expenditureEconomicId[0].required = false
  // 设置经济分类
  expenditureEconomicList.value = []
  available.value = null
  if (expenditureKpiObj.value.isEconomic === '1') {
    let expenditureKpiItemList = await doGet(svc, '/expenditure-kpi-item/listByField', {
      field: 'expenditureKpiId',
      values: obj.value.expenditureKpiId
    }, false)
    let expenditureEconomicIds = []
    expenditureKpiItemList?.map(item => {
      item.expenditureEconomicId.split(',').map(m => {
        if (!expenditureEconomicIds.includes(m)) {
          expenditureEconomicIds.push(m)
        }
      })
    })
    expenditureEconomicList.value = await doGet(svc, '/expenditure-economic/ids', {ids: expenditureEconomicIds.join(',')}, false)
    rules.value.expenditureEconomicId[0].required = true
  }
}
const chooseExpenditureApplication = () => {
  if (!expenditureKpiObj.value.id) {
    alertWarningMsg('请先选择指标单')
    return
  }
  applicationVisible.value = true
}
const changeExpenditureApplication = async (data) => {
  expenditureApplicationObj.value = data
  expenditureApplicationObj.value.availableAmount = await doGet(svc, '/customExpenditureExpenses/queryExpenditureApplicationAvailableAmount', {expenditureApplicationId: data.id}, false)
  obj.value.expenditureApplicationId = data.id
  // 设置经济分类
  if (expenditureKpiObj.value.isEconomic === '1') {
    let expenditureEconomicIds = []
    data.expenditureEconomicId.split(',').map(m => {
      if (!expenditureEconomicIds.includes(m)) {
        expenditureEconomicIds.push(m)
      }
    })
    expenditureEconomicList.value = await doGet(svc, '/expenditure-economic/ids', {ids: expenditureEconomicIds.join(',')}, false)
    rules.value.expenditureEconomicId[0].required = true
  }
}

const selectAttachmentFn = (list) => {
  console.debug('list-------------', list)
  if (list.length > 0) {
    list.forEach(item => {
      item.original = item.fileName
      item.size = item.fileSize
      oFiles.value.push(item)
    })
  }
  // oFiles.value = [oFiles.value, ...list]
  console.debug('oFiles.value', oFiles.value)
  oFiles.value = Array.from(new Set(oFiles.value))
}

const uploadedSuccessFn = (file) => {
  console.debug('file-----------',file)
  oFiles.value.push(file)
}

async function checkForm(callback) {
  let tab1Valid = await objForm.value.validate().catch((err)=>{return err})
  if (tab1Valid !== true) {
    alertErrorMsg('报账信息表单验证不通过，请检查数据。')
    return
  }
  if (!obj.value.expenditureApplicationId) {
    // alertErrorMsg('请选择事前用款申请单')
    // return
  }
  callback()
}

const handleSave = () => {
  checkForm(() => {
    let o = buildObj()
    doPost(svc, '/customExpenditureExpenses/saveExpenditureReimbursement', o, true).then(() => {
      notifySuccess('保存成功')
      ctx.$tab.closeOpenPage({ path: '/expenditure/expenses/expenditureReimbursementOther', query: {} })
      dialogViewVisible.value = false
    })
  })
}

const handleSubmit = () => {
  checkForm(() => {
    let o = buildObj()
    doPost(svc, '/customExpenditureExpenses/saveExpenditureReimbursement', o, false).then(res => {
      obj.value.id = res['id']
      obj.value.version = res['version']
      dialogApproveVisible.value = true
    })
  })
}

const doSubmit = async (data) => {
  if (obj.value.amount > expenditureApplicationObj.value.availableAmount) {
    alertErrorMsg('提交报账金额[' + obj.value.amount + ']不能超过事前用款申请单的剩余金额')
    return;
  }
  let o = buildObj()
  o.approveId = data.approveId
  o.approveNodes = data.approveNodes
  doPost(svc, '/customExpenditureExpenses/submitExpenditureReimbursement', o, true).then(() => {
    notifySuccess('提交成功')
    ctx.$tab.closeOpenPage({ path: '/expenditure/expenses/expenditureReimbursementOther', query: {} })
    dialogViewVisible.value = false
  })
}

const supplementInfo = async () => {
  let v1 = await incomeForm.value[0].validate().catch((err)=>{return err})
  let v2 = await outcomeForm.value[0].validate().catch((err)=>{return err})
  if (v1 !== true || v2 !== true) {
    alertErrorMsg('收支信息录入验证不通过，请检查数据。')
    return
  }
  let o = supplementBuildObj()
  doPost(svc, '/customExpenditureExpenses/replenishExpenditureReimbursement', o).then(() => {
    notifySuccess('提交成功')
    ctx.$tab.closeOpenPage({ path: '/expenditure/expenses/expenditureReimbursementOther', query: {} })
  })
}

const supplementBuildObj = () => {
  let o = {
    amount: obj.value.amount, // 金额
    applicationOrganizationId: obj.value.applicationOrganizationId,// 申请人部门ID
    applicationUserId: obj.value.applicationUserId, // 申请人用户ID
    expenditureApplicationId: obj.value.expenditureApplicationId,// 事前用款申请单ID
    expenditureEconomicId: Array.isArray(obj.value.expenditureEconomicId) ? obj.value.expenditureEconomicId.join(',') : obj.value.expenditureEconomicId,// 经济分类ID
    expenditureKpiId: obj.value.expenditureKpiId,// 指标单表ID
    expenditureSubjectId: Array.isArray(obj.value.expenditureSubjectId) ? obj.value.expenditureSubjectId.join(',') : obj.value.expenditureSubjectId,// 会计科目ID
    id: obj.value.id,
    reimbursementCode: obj.value.reimbursementCode, // 报账单号
    reimbursementDate: obj.value.reimbursementDate,// 报账日期
    reimbursementType: obj.value.reimbursementType,// 报账单类型
    remark: obj.value.remark, // 备注
    settlement: obj.value.settlement,// 结算方式
    state: obj.value.state, // 状态
  }
  o.pays = pays.value
  o.payees = payees.value
  return o
}

const buildObj = () => {
  obj.value.expenditureEconomicId = obj.value.expenditureEconomicId instanceof Array ? obj.value.expenditureEconomicId.join(',') : obj.value.expenditureEconomicId
  obj.value.expenditureSubjectId = obj.value.expenditureSubjectId instanceof Array ? obj.value.expenditureSubjectId.join(',') : obj.value.expenditureSubjectId
  // obj.value.pays = pays.value
  // obj.value.payees = payees.value
  obj.value.pays = []
  if (pays.value.length > 0) {
    pays.value.map(pay => {
      if (!isNullOrUndefinedOrEmpty(pay.payType)
          || !isNullOrUndefinedOrEmpty(pay.settleType)
          || !isNullOrUndefinedOrEmpty(pay.payAccount)
          || !isNullOrUndefinedOrEmpty(pay.pay)
          || !isNullOrUndefinedOrEmpty(pay.amount)
          || !isNullOrUndefinedOrEmpty(pay.paySummary)) {
        pay.amount = obj.value.amount
        obj.value.pays.push(pay)
      }
    })
  }
  obj.value.payees = []
  if (payees.value.length > 0) {
    payees.value.map(payee => {
      if (!isNullOrUndefinedOrEmpty(payee.payeeType)
          || !isNullOrUndefinedOrEmpty(payee.expenditureProceedsId)
          || !isNullOrUndefinedOrEmpty(payee.proceedsCompany)
          || !isNullOrUndefinedOrEmpty(payee.proceedsBank)
          || !isNullOrUndefinedOrEmpty(payee.proceedsAccount)
          || !isNullOrUndefinedOrEmpty(payee.expenditureBusinessCardId)
          || !isNullOrUndefinedOrEmpty(payee.businessCardName)
          || !isNullOrUndefinedOrEmpty(payee.businessCardBank)
          || !isNullOrUndefinedOrEmpty(payee.businessCardAccount)
          || !isNullOrUndefinedOrEmpty(payee.payeeSummary)) {
        payee.amount = obj.value.amount
        obj.value.payees.push(payee)
      }
    })
  }
  obj.value.files = []
  if (oFiles.value.length > 0) {
    console.debug('this.oFiles.value',oFiles.value)
    obj.value.files = oFiles.value.map(item => {
      if (obj.value.id) {
        return {
          attachmentId: item.id,
          attachmentName: item?.original,
          attachmentType: item?.attachmentType,
          expenditureReimbursementId: obj.value.id
        }
      } else {
        return {
          attachmentId: item.id,
          attachmentName: item?.original,
          attachmentType: item?.attachmentType
        }
      }
    })
  }
  console.debug('obj.value-------------',obj.value)
  return obj.value
}
const changeProceeds = (obj) => {
  expenditureProceedsItem.value = obj
  payees.value[0].expenditureProceedsId = obj.id;
  payees.value[0].proceedsCompany = obj.name;
  payees.value[0].proceedsBank = obj.bankId;
  payees.value[0].proceedsAccount = obj.account;
  payees.value[0].expenditureBusinessCardId = null;
  payees.value[0].businessCardName = null;
  payees.value[0].businessCardBank = null;
  payees.value[0].businessCardAccount = null;
}
const changeBusinessCard = (obj) => {
  payees.value[0].expenditureProceedsId = null;
  payees.value[0].proceedsCompany = null;
  payees.value[0].proceedsBank = null;
  payees.value[0].proceedsAccount = null;
  payees.value[0].expenditureBusinessCardId = obj.id;
  payees.value[0].businessCardName = obj.cardName;
  payees.value[0].businessCardBank = obj.bankId;
  payees.value[0].businessCardAccount = obj.account;
}
const downloadFile = (row) => {
  doDownload(svc, `/customAttachment/download/${row.attachmentId}`, {})
}

const expenseTypeFn = (value) => {
  console.debug('value------------',value)
}
const handleSelectionChange = (val) => {
  console.debug('val',val)
}
const downloadFile1 = (row) => {
  console.debug('row',row)
  if (row.attachmentId) {
    doDownload(svc, `/customAttachment/download/${row.attachmentId}`, {})
  } else {
    doDownload(svc, `/customAttachment/download/${row.id}`, {})
  }
}
const viewFile1 = (row) => {
  attachmentVisible.value = true
  setTimeout(() => {
    if (row.attachmentId) {
      previewAttachmentId.value = row.attachmentId
    } else {
      previewAttachmentId.value = row.id
    }
    console.debug('previewAttachmentId.value',previewAttachmentId.value)
  },100)
}
const removeFile1 = (scope) => {
  oFiles.value.splice(scope.$index, 1)
}

function changeExpenditureEconomicId() {
  let o = obj.value.expenditureEconomicId
  if (o?.length > 0) {
    let para = {
      expenditureKpiId: obj.value.expenditureKpiId,
      expenditureEconomicId: o?.join(","),
      useFluctuateStr: "false",
    }
    doGet(svc, '/customExpenditureKpis/queryExpenditureKpiAvailableAmount', para, false).then(res => {
      available.value = res
    })
  }
}
</script>
<style scoped>
td,th {
  padding: 20px 0;
}
.report-form {
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  background: #fff;
  z-index: 10;
  padding: 20px;
  overflow-x: hidden;
  overflow-y: auto;
}
.report-form-content-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.update-log {
  width: 100%;
  margin: 30px 0;
}
.file-list-btn {
  display: flex;
  align-items: center;
  justify-content: space-between
}
.file-list-btns {
  display: flex;
  align-items: center;
}
.file-list-btn-span {
  color: #F56C6C;
  font-size: 12px;
}
</style>
